<script setup>
import { forEach } from 'lodash-es';
import { useWatch } from '@/hooks/useWatch';
const props = defineProps({
  data: { type: Array, default: () => [] },
  buildData: { type: Array, default: () => null },
});
const treeRef = ref(null);

const isdisabledFn = () => {
  return true;
};
const defaultProps = {
  // 默认设置
  children: 'children',
  label: 'name',
  disabled: isdisabledFn,
};
useWatch(
  () => props.data,
  n => {
    if (!n) {
      forEach(treeRef.value, n => {
        nextTick(() => {
          if (n) n.setCheckedKeys([]);
        });
      });
    }
  },
  { deep: true, immediate: true },
);
</script>
<template>
  <div class="u-prim-text">
    <div class="ad-wrapper">
      <div class="khzb-left">
        <el-table :data="data ?? []" :height="360" border>
          <el-table-column label="托管年份" align="center" min-width="120">
            <template slot-scope="scope">
              {{ scope.row?.year?.slice(0, 4) }}
            </template>
          </el-table-column>
          <el-table-column
            v-for="(el, columnInd) in data[0]?.basiss ?? []"
            :key="columnInd"
            :label="el.basisTypeName"
            align="center"
          >
            <el-table-column :label="'基准能耗（' + el.basisTypeUnit + '）'" min-width="160" align="center">
              <template slot-scope="scope">
                <span :class="data?.[scope.$index]?.basiss?.[columnInd]?.isAlterationQuantity ? 'red' : ''">
                  {{ data[scope.$index].basiss[columnInd].basisQuantity }}
                </span>
              </template>
            </el-table-column>
            <el-table-column prop="basisCost" label="基准费用（元）" min-width="160" align="center">
              <template slot-scope="scope">
                <span :class="data?.[scope.$index]?.basiss?.[columnInd]?.isAlterationCost ? 'red' : ''">
                  {{ data[scope.$index].basiss[columnInd].basisCost }}
                </span>
              </template>
            </el-table-column>
          </el-table-column>
        </el-table>
      </div>
      <div class="khzb-right">
        <div class="title-top u-df-st">
          <span class="red">*</span>
          关联区域
        </div>
        <el-tree
          ref="treeRef"
          :data="buildData ?? []"
          :props="defaultProps"
          :highlight-current="true"
          :check-strictly="true"
          show-checkbox
          :default-checked-keys="data?.[0]?.area ?? []"
          node-key="id"
          class="u-p20 mtree"
          default-expand-all
        >
          <span class="custom-tree-node u-fs14" slot-scope="{ node, data }">
            <!-- <ToolTip class="tree-lable u-pr20" :content="data.name" effect="dark" /> -->
            <span class="tree-lable u-pr20">{{ data.name }}</span>
          </span>
        </el-tree>
      </div>
    </div>
    <div>
      <el-input type="textarea" :rows="3" v-model="data[0].basiss[0].remark" :disabled="true"></el-input>
    </div>
    <div class="u-mt20 u-mb20 u-df-st">
      <span class="u-pr20">操作人：{{ data?.[0]?.createPerson ?? '-' }}</span>
      <span>操作时间：{{ data?.[0]?.createTime ?? '-' }}</span>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.ad-wrapper {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  margin-bottom: 20px;
  .title-top {
    width: 100%;
    padding-left: 20px;
    height: 48px;
  }
  .khzb-left {
    width: calc(60% + 22px);
    margin-right: 20px;
  }
  .khzb-right {
    width: calc(40% - 22px);

    height: 360px;
    overflow-y: scroll;
    .title-top {
      border-bottom: 1px solid #374468;
    }
  }
}
.app-dark {
  .khzb-left {
    .title-top {
      background: #242b41;
      border: 1px solid #374468;
      border-bottom: none;
    }
  }
  .khzb-right {
    border: 1px solid #374468;
    .title-top {
      background: #242b41;
      border-bottom: 1px solid #374468;
    }
  }
}
.app-light {
  .khzb-left {
    .title-top {
      background: #f5f7fa;
      border: 1px solid #eee;
      border-bottom: none;
    }
  }
  .khzb-right {
    border: 1px solid #eee;
    .title-top {
      background: #f5f7fa;
      border-bottom: 1px solid #eee;
    }
  }
}
.red {
  color: #ff0000;
}
.mtree {
  height: calc(100% - 48px);
  overflow-y: scroll;
}
</style>
